import 'package:dio/dio.dart';
import 'package:flutter/material.dart';

class Girdviewcomp extends StatefulWidget {
  const Girdviewcomp({super.key});

  @override
  State<Girdviewcomp> createState() => _GirdviewcompState();
}

class _GirdviewcompState extends State<Girdviewcomp> {
  List navList = [];

  @override
  void initState() {
    super.initState();
  }

  getResData() async {
    Dio dio = Dio();
    Response res = await dio
        .get('http://smart-shop.itheima.net/index.php?s=/api/page/detail');
    setState(() {
      // 2.3 导航组数据
      navList = res.data['items'][3]['data'];
      // 2.4 广告图片数据
    });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.center,
      width: double.infinity,
      height: 200,
      color: Colors.yellow,
      padding: const EdgeInsets.all(10),
      child: Column(
        children: [
          GridView.builder(
            gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 4, //列数
              mainAxisSpacing: 10, //主轴间距
              crossAxisSpacing: 10, //侧轴间距
            ),
            itemCount: 10, //宫格数量
            itemBuilder: (context, index) {
              return Container(
                color: Colors.white,
                child: Column(
                  children: [
                    Image.network(navList[index]['image']),
                    Text(navList[index]['name']),
                  ],
                ),
              );
            },
          ),
        ],
      ),
    );
  }
}
